/**
 * Created by Administrator on 2018/7/25.
 */
$CertusJsonAjax.ajax("queryContractTrace", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.processCCBXTrace = res.data;
})

$$scope.moneyChange = function(money,b,c){
    $$scope.contractInfo[c+"Date"] = "";
    initDatePicker(b,c);
}

function initDate(a,b,c){

    var picker34 = $(b).datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.contractInfo[c+"Date"] = result;
            $$scope.$apply();
        }
    })
    $(a).focus();
}

$$scope.moneyChange = function(money,b,c){
    $$scope.contractInfo[c+"Date"] = "";
    initDatePicker(b,c);
}

function initDate(a,b,c){

    var picker34 = $(b).datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.contractInfo[c+"Date"] = result;
            $$scope.$apply();
        }
    })
    $(a).focus();
}

$CertusJsonAjax.ajax("contractInfoBacklog", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.contractInfo = res.data.contractInfo;
    $$scope.contractInfo.contractSignTime = $$filter("date")($$scope.contractInfo.contractSignTime, "yyyy-MM-dd");
    $$scope.projInfo = res.data.projInfo;
    $$scope.contractInfo.initialPaymentDate = $$filter("date")($$scope.contractInfo.initialPaymentDate, "yyyy-MM-dd");
    $$scope.contractInfo.preliminaryInspectionDate = $$filter("date")($$scope.contractInfo.preliminaryInspectionDate, "yyyy-MM-dd");
    $$scope.contractInfo.finalAcceptanceDate = $$filter("date")($$scope.contractInfo.finalAcceptanceDate, "yyyy-MM-dd");
    $$scope.contractInfo.finalPaymentDate = $$filter("date")($$scope.contractInfo.finalPaymentDate, "yyyy-MM-dd");
    debugger;
    $$scope.contractInfo.compCodeSelect = [
        {"name":"赛特斯信息科技股份有公司         ","code":"赛特斯信息科技股份有公司        "},
        {"name":"上海赛特斯信息科技股份有限公司   ","code":"上海赛特斯信息科技股份有限公司  "},
        {"name":"上海美琦浦悦众创空间管理有限公司 ","code":"上海美琦浦悦众创空间管理有限公司"},
        {"name":"北京赛特斯信息科技股份有限公司   ","code":"北京赛特斯信息科技股份有限公司  "},
        {"name":"南通美琦湳悦通讯科技有限公司     ","code":"南通美琦湳悦通讯科技有限公司    "},
        {"name":"广东赛特斯信息科技有限公司       ","code":"广东赛特斯信息科技有限公司      "},
        {"name":"netelastic. System Inc           ","code":"netelastic. System Inc          "},
        {"name":"上海浩方信息技术有限公司         ","code":"上海浩方信息技术有限公司        "},
        {"name":"上海浩方科技有限公司             ","code":"上海浩方科技有限公司            "}
    ]
})

$$scope.getState = function (a) {

    if (a == "1") {
        return "运行中"
    } else if (a == "2") {
        return "已关闭"
    } else if (a == "3") {
        return "已完结"
    } else if (a == "4") {
        return "已暂停"
    }
}


$$scope.getProjLv = function (projLv) {
    if (projLv == "1") {
        return "低";
    } else if (projLv == "2") {
        return "中";
    } else if (projLv == "3") {
        return "高"
    }
}




$$scope.contractInfoApproval = function () {

    if (certusValidateNotnull()) {
        $$scope.contractInfo.originReason = "approval";
        $$scope.contractInfo.processInstanceId = $CertusJsonAjax.getProInstanceId();
        $$scope.contractInfo.stepInstanceId = $CertusJsonAjax.getStepInstanceId();

        $CertusJsonAjax.ajax("secondContractInfo", $$scope.contractInfo, function (res) {
            if (res.data) {
                findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
                history.back();
                return;
            }
        })

    }

}

$$scope.contractInfoDenied = function () {
    $$scope.contractInfo.originReason = "denied"
    $CertusJsonAjax.ajax("unPromiseContractInfo", $$scope.contractInfo, function (res) {
        if (res.data) {
            if (res.data == "success") {
                window.history.back()
            }
        }
    })
}